package com.gaogzhen.datastructure.symbolTable;

import java.util.Iterator;

/**
 * @author Administrator
 * @version 1.0
 * @description
 * @date 2022-11-11 20:14
 */
public abstract class AbstractST<K, V> implements ST<K, V>{
    @Override
    public String toString() {
        Iterable<K> iterable = keys();
        Iterator<K> iterator;
        if (iterable == null || !((iterator = iterable.iterator()).hasNext())) {
            return "{}";
        }
        StringBuilder sb = new StringBuilder();
        sb.append("{");
        while (true) {
            K k = iterator.next();
            V v = get(k);
            sb.append(k).append("=").append(v);
            if (!iterator.hasNext()) {
                sb.append("}");
                return sb.toString();
            }
            sb.append(", ");
        }
    }
}
